import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_bloc_demo/config/config_bloc.dart';
import 'package:flutter_bloc_demo/routers.dart';

///此类演示全局bloc的使用
void main() {
  runApp(
    MultiBlocProvider(
      providers: [
        BlocProvider<ConfigBloc>(
          create: (BuildContext context) {
            return ConfigBloc();
          },
        ),
      ],
      child: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ConfigBloc, ConfigState>(
      builder: (BuildContext context, ConfigState state) => MaterialApp(
        routes: Routers.routers,
        initialRoute: "/",
        theme: ThemeData(
          appBarTheme: AppBarTheme(
            color: state.appBarColor,
          ),
          textTheme: TextTheme(
            bodyText1: TextStyle(
              color: state.textColor,
            ),
            bodyText2: TextStyle(
              color: state.textColor,
            ),
          ),
        ),
      ),
    );
  }
}
